from selenium import webdriver
from HTMLReport import logger, AddImage


def get_browser():
    """获取一个浏览器实例

    :return: 浏览器实例
    """
    # driver = webdriver.Chrome()
    driver = webdriver.Remote(
        command_executor='http://192.168.2.111:4444/wd/hub',  # HUB的地址
        desired_capabilities=webdriver.DesiredCapabilities.CHROME
    )
    logger().info(f"打开浏览器：{driver.name}")
    driver.maximize_window()
    logger().info('最大化浏览器窗口')
    driver.implicitly_wait(3)
    logger().info('设置隐式等待')
    return driver


def add_image(driver):
    """添加截图到报告中

    :param driver:
    :return:
    """
    AddImage(driver.get_screenshot_as_base64())
